package com.ruoyi.wechat.api;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.wechat.domain.Campsite;
import com.ruoyi.wechat.service.ICampsiteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 营地营位表Controller
 *
 * @author ruoyi
 * @date 2024-10-29
 */
@RestController
@RequestMapping("/wechatt/campsite")
public class WxCampsiteController extends BaseController {

    @Autowired
    private ICampsiteService campsiteService;

    /**
     * 查询营地营位表列表
     */

    @GetMapping("/list")
    public TableDataInfo list(Campsite campsite)
    {
        startPage();
        List<Campsite> list = campsiteService.selectCampsiteList(campsite);
        return getDataTable(list);
    }
    @GetMapping("/list/{id}")
    public Campsite getCampCampsite(@PathVariable String id)
    {
        return campsiteService.selectCampsiteByCampId(id);
    }


    /**
     * 获取营地营位表详细信息
     */

    @GetMapping(value = "/{campsiteId}")
    public AjaxResult getInfo(@PathVariable("campsiteId") String campsiteId)
    {
        return success(campsiteService.selectCampsiteByCampsiteId(campsiteId));
    }

    /**
     * 新增营地营位表
     */

    @Log(title = "营地营位表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Campsite[] campsite)
    {
        return toAjax(campsiteService.insertCampsite(campsite));
    }

    /**
     * 修改营地营位表
     */

    @Log(title = "营地营位表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Campsite campsite)
    {
        return toAjax(campsiteService.updateCampsite(campsite));
    }

    /**
     * 删除营地营位表
     */

    @Log(title = "营地营位表", businessType = BusinessType.DELETE)
    @DeleteMapping("/{campsiteId}")
    public AjaxResult remove(@PathVariable String campsiteId)
    {
        return toAjax(campsiteService.deleteCampsiteByCampsiteId(campsiteId));
    }
}
